package com.example.controller;

import com.example.config.ResponseEntity;
import com.example.entity.Role;
import com.example.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/role")
@CrossOrigin
public class RoleController {

    @Autowired
    RoleService roleService;

    @GetMapping("/getall")
    public ResponseEntity getRoles(){
        return ResponseEntity.success(roleService.getRoles());
    }

    @GetMapping("/getById/{id}")
    public ResponseEntity getRoleById(@PathVariable("id") int id){
        return ResponseEntity.success(roleService.getRoleById(id));
    }

    @PostMapping("/save")
    public ResponseEntity saveRole(@RequestBody Role role){
        System.out.println(role);
        roleService.saveRole(role);
        return ResponseEntity.success();
    }
}
